<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Dashboard 调试工具</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 20px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
        }
        .container {
            max-width: 800px;
            margin: 0 auto;
            background: rgba(255, 255, 255, 0.1);
            padding: 30px;
            border-radius: 15px;
            backdrop-filter: blur(10px);
        }
        .test-section {
            margin: 20px 0;
            padding: 20px;
            background: rgba(255, 255, 255, 0.1);
            border-radius: 10px;
            border: 1px solid rgba(255, 255, 255, 0.2);
        }
        button {
            background: linear-gradient(45deg, #ff6b6b, #ee5a24);
            color: white;
            border: none;
            padding: 12px 24px;
            border-radius: 8px;
            cursor: pointer;
            margin: 5px;
            font-size: 14px;
            transition: all 0.3s ease;
        }
        button:hover {
            transform: translateY(-2px);
            box-shadow: 0 5px 15px rgba(0,0,0,0.3);
        }
        .status {
            margin: 10px 0;
            padding: 10px;
            border-radius: 5px;
            background: rgba(0, 0, 0, 0.2);
        }
        .success { background: rgba(76, 175, 80, 0.3) !important; }
        .error { background: rgba(244, 67, 54, 0.3) !important; }
        .info { background: rgba(33, 150, 243, 0.3) !important; }
    </style>
</head>
<body>
    <div class="container">
        <h1>🔧 Dashboard 白屏问题调试工具</h1>
        
        <div class="test-section">
            <h3>📊 当前状态检查</h3>
            <div id="status" class="status info">
                正在检查当前状态...
            </div>
            <button onclick="checkCurrentStatus()">🔍 检查当前状态</button>
        </div>

        <div class="test-section">
            <h3>🔑 认证问题解决方案</h3>
            <p>如果Dashboard页面闪现后变白，很可能是认证token问题：</p>
            <button onclick="setTestToken()">✅ 设置测试Token</button>
            <button onclick="clearToken()">❌ 清除Token</button>
            <button onclick="checkToken()">🔍 检查Token状态</button>
        </div>

        <div class="test-section">
            <h3>🚀 快速测试方案</h3>
            <button onclick="testBasicRoute()">🎯 测试基础路由</button>
            <button onclick="testWithToken()">🔐 带Token测试Dashboard</button>
            <button onclick="testDirectAccess()">🎪 直接访问Dashboard</button>
        </div>

        <div class="test-section">
            <h3>🛠️ 高级调试</h3>
            <button onclick="openDevTools()">🔧 打开开发者工具</button>
            <button onclick="checkConsoleErrors()">📝 检查控制台错误</button>
            <button onclick="analyzeNetwork()">🌐 分析网络请求</button>
        </div>

        <div class="test-section">
            <h3>📋 问题报告</h3>
            <div id="report" class="status info">
                点击上方按钮开始诊断...
            </div>
        </div>
    </div>

    <script>
        function updateStatus(message, type = 'info') {
            const status = document.getElementById('status');
            status.textContent = message;
            status.className = `status ${type}`;
        }

        function updateReport(message, type = 'info') {
            const report = document.getElementById('report');
            report.innerHTML += `<div class="${type}">[${new Date().toLocaleTimeString()}] ${message}</div>`;
        }

        function checkCurrentStatus() {
            const token = localStorage.getItem('admin_token');
            const location = window.location.href;
            
            let status = '当前状态:\n';
            status += `• 页面地址: ${location}\n`;
            status += `• Token状态: ${token ? '✅ 已设置' : '❌ 未设置'}\n`;
            status += `• Token值: ${token || '无'}\n`;
            status += `• 时间: ${new Date().toLocaleString()}`;
            
            updateStatus(status, token ? 'success' : 'error');
            updateReport(`状态检查完成 - Token: ${token ? '存在' : '缺失'}`, token ? 'success' : 'error');
        }

        function setTestToken() {
            localStorage.setItem('admin_token', 'debug-test-token-' + Date.now());
            updateStatus('✅ 测试Token已设置', 'success');
            updateReport('设置了测试Token', 'success');
        }

        function clearToken() {
            localStorage.removeItem('admin_token');
            updateStatus('❌ Token已清除', 'info');
            updateReport('Token已清除', 'info');
        }

        function checkToken() {
            const token = localStorage.getItem('admin_token');
            updateStatus(`Token: ${token || '未设置'}`, token ? 'success' : 'error');
            updateReport(`Token检查: ${token || '未找到'}`, token ? 'success' : 'error');
        }

        function testBasicRoute() {
            updateReport('正在测试基础路由...', 'info');
            window.open('/dashboard', '_blank');
        }

        function testWithToken() {
            setTestToken();
            setTimeout(() => {
                updateReport('带Token测试Dashboard...', 'info');
                window.open('/dashboard', '_blank');
            }, 500);
        }

        function testDirectAccess() {
            updateReport('直接访问Dashboard...', 'info');
            window.location.href = '/dashboard';
        }

        function openDevTools() {
            updateReport('请手动按F12打开开发者工具', 'info');
            alert('请按F12打开开发者工具，然后查看Console和Network标签页');
        }

        function checkConsoleErrors() {
            updateReport('请在开发者工具Console中查看错误信息', 'info');
            console.log('=== Dashboard 调试信息 ===');
            console.log('Token:', localStorage.getItem('admin_token'));
            console.log('Location:', window.location.href);
            console.log('User Agent:', navigator.userAgent);
            console.log('=========================');
        }

        function analyzeNetwork() {
            updateReport('请在开发者工具Network标签页中查看网络请求', 'info');
            fetch('/dashboard').then(response => {
                console.log('Dashboard请求状态:', response.status);
                updateReport(`Dashboard请求状态: ${response.status}`, response.ok ? 'success' : 'error');
            }).catch(error => {
                console.error('Dashboard请求错误:', error);
                updateReport(`Dashboard请求错误: ${error.message}`, 'error');
            });
        }

        // 页面加载时自动检查状态
        window.onload = function() {
            checkCurrentStatus();
            updateReport('调试工具已加载', 'success');
        };
    </script>
</body>
</html>